//
//  YJDOrderLBL.m
//  YJDSDK
//
//  Created by tucici on 2017/12/5.
//  Copyright © 2017年 SKL. All rights reserved.
//

#import "YJDOrderLBL.h"
typedef NS_ENUM(NSInteger , OrderLBLType)
{
    titleType = 1,
    imageType
};
@interface YJDOrderLBL ()
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) YJDLabel *titleLBL;
@property (nonatomic, strong) YJDImageView *IMG;
@property (nonatomic, strong) YJDLabel *contentLBL;
@property (nonatomic, strong) YJDLabel *descrLBL;
@property (nonatomic, assign) OrderLBLType type;
@end
@implementation YJDOrderLBL

- (instancetype)initWithTitle:(NSString *)title
{
    self = [super init];
    if (self)
    {
        self.titleLBL.text = title;
        self.line.hidden = NO;
        self.type = titleType;
    }
    return self;
}

- (instancetype)initWithImageName:(NSString *)imageName
{
    self = [super init];
    if (self)
    {
//        self.IMG.imageName = imageName;
      UIImage *image = [UIImage imageNamed:@"game_icon.png"];
        self.IMG.image = image;
        self.line.hidden = NO;
        self.type = imageType;
    }
    return self;
}
- (UIView *)line
{
    if (!_line)
    {
        _line = [[UIView alloc]init];
        _line.backgroundColor = RGBA(223, 223, 223, 1.0);
        [self addSubview:_line];
        [_line mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.right.equalTo(self);
            make.bottom.equalTo(self);
            make.height.mas_equalTo(1);
        }];
    }
    return _line;
}

- (YJDLabel *)contentLBL
{
    if (!_contentLBL)
    {
        _contentLBL = [[YJDLabel alloc]init];
        _contentLBL.textColor = [UIColor blackColor];
        _contentLBL.font = [UIFont systemFontOfSize:15 weight:UIFontWeightLight];
        [self addSubview:_contentLBL];
    }
    return _contentLBL;
}

- (YJDLabel *)descrLBL
{
    if (!_descrLBL)
    {
        _descrLBL = [[YJDLabel alloc]init];
        _descrLBL.textColor = [UIColor lightGrayColor];
        _descrLBL.font = [UIFont systemFontOfSize:13 weight:UIFontWeightLight];
        [self addSubview:_descrLBL];
    }
    return _descrLBL;
}

- (YJDLabel *)titleLBL
{
    if (!_titleLBL)
    {
        _titleLBL = [[YJDLabel alloc]init];
        _titleLBL.textColor =  RGBA(109, 109, 109, 1.0);
        _titleLBL.font = [UIFont systemFontOfSize:17 weight:UIFontWeightBold];
        [self addSubview:_titleLBL];
        [_titleLBL mas_updateConstraints:^(SK_MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(_titleLBL.bounds.size);
        }];
    }
    return _titleLBL;
}

- (YJDImageView *)IMG
{
    if (!_IMG)
    {
        _IMG = [[YJDImageView alloc]init];
        _IMG.layer.cornerRadius = 5.0;
        _IMG.layer.masksToBounds = YES;
        [self addSubview:_IMG];
        [_IMG mas_makeConstraints:^(SK_MASConstraintMaker *make) {
            make.left.equalTo(self);
            make.centerY.equalTo(self);
            make.size.mas_equalTo(CGSizeMake(30, 30));
        }];
    }
    return _IMG;
}

- (void)setType:(OrderLBLType)type
{
    if (_type != type)
    {
        _type = type;
        if (_type == titleType)
        {
            self.contentLBL.hidden = NO;
            [self.contentLBL mas_makeConstraints:^(SK_MASConstraintMaker *make) {
                make.left.equalTo(_titleLBL.mas_right).with.offset(10);
                make.centerY.equalTo(self);
            }];
        }
        else
        {
            self.contentLBL.hidden = NO;
            self.descrLBL.hidden = NO;
            [self.contentLBL mas_makeConstraints:^(SK_MASConstraintMaker *make) {
                make.left.equalTo(_IMG.mas_right).with.offset(10);
                make.bottom.equalTo(self.mas_centerY);
            }];
            [self.descrLBL mas_makeConstraints:^(SK_MASConstraintMaker *make) {
                make.left.equalTo(_IMG.mas_right).with.offset(10);
                make.top.equalTo(self.mas_centerY);
            }];
        }
    }
}
- (void)setContent:(NSString *)content
{
    if (_content != content)
    {
        _content = content;
        self.contentLBL.text = content;
    }
}

- (void)setDescr:(NSString *)descr
{
    if (_descr != descr)
    {
        _descr = descr;
        self.descrLBL.text = descr;
    }
}
/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
